<!-- BEGIN PAGE HEADER-->
<?php $this->load->view('partials/breadcrumb.tpl') ?>
<!-- END PAGE HEADER-->
<style>
    body > div.page-container > div.page-content-wrapper > div > div.page-bar > div > div {
        display: none;
    }
</style>
<div class="row">
    <div class="col-xs-12">
        <!-- Begin: life time stats -->
        <div class="portlet">
            <?= form_open('', Array('class' => 'form-inline', 'role' => 'form')) ?>

            <div style="clear:both;height:14px;"></div>
            <!--            --><? //= search_form_input('ip_number_perpage', filterValue('ip_number_perpage'), '每页显示条数', 'class="form-control input-xs"'); ?>
            <!---->
            <!--            <div class="input-group input-large date-picker input-daterange" data-date="" data-date-format="yyyy-mm-dd">-->
            <!--                <input type="text" class="form-control" name="ip_create_time_begin" value="-->
            <? //= filterValue('ip_create_time_begin') ?><!--" placeholder="IP录入开始时间" autoComplete="off">-->
            <!--                <span class="input-group-addon">to </span>-->
            <!--                <input type="text" class="form-control" name="ip_create_time_end" value="-->
            <? //= filterValue('ip_create_time_end') ?><!--" placeholder="IP录入结束时间" autoComplete="off">-->
            <!---->
            <!--            </div>-->
            <?= search_form_input('ip', filterValue('ip'), 'IP地址', 'class="form-control"'); ?>

            <button type="submit" class="btn green about_search">检索 <i class="fa fa-search"></i></button>
            <button type="button" class="btn default" id="reset">重置</button>
            <button id="import_xls" type="button" class="btn blue">IP导入</button>

            <?= form_close() ?>
            <div class="portlet-body">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="table-scrollable">
                            <?php if (count($list)): ?>
                                <form action="<?= site_url('shipping/warehouse_out/add') ?>" method="post" id="app-ids">
                                    <table class="table table-striped table-bordered table-hover">
                                        <thead class="flip-content">
                                        <tr>
                                            <th>ID</th>
                                            <th>IP地址</th>
                                            <th>备注</th>
                                            <th>创建时间</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <?php foreach ($list as $v) { ?>
                                            <tr>
                                                <td class="numeric"><?= $v->id ?></td>
                                                <td class="numeric"><?= $v->ip ?></td>
                                                <td class="numeric"><?= $v->remark ?></td>
                                                <td class="numeric"><?= date('Y-m-d H:i', $v->create_time) ?></td>

                                            </tr>
                                        <?php } ?>
                                        </tbody>
                                    </table>
                                </form>
                            <?php else: ?>
                                <p style="padding: 15px;font-size: 15px;text-align: center;margin-bottom: -15px;
">暂无IP为：<span style="color: red;"><?= $search_ip ?></span> 的使用记录</p>
                            <?php endif; ?>
                            <?php if (count($list) == 0 && $search_ip !== ''): ?>
                                <?= form_open('', Array('class' => 'form-inline text-center', 'id' => 'bindIp', 'role' => 'form', 'style' => 'padding:10px')) ?>
                                <div style="clear:both;height:14px;"></div>

                                <div class="form-group text-center">
                                    <label class="">IP地址：</label>
                                    <input type="text" readonly name="ip" value="<?= $search_ip ?>" placeholder="IP地址"
                                           class="form-control">
                                    <input type="hidden" name="user_id" value="<?= $this->_user->id ?>">
                                </div>
                                <div class="form-group">
                                    <label class="">使用账户：</label>
                                    <input type="text" name="remark" class="form-control">
                                </div>
                                <button type="button" id="ip-bind" class="btn purple about_search">确认使用 <i
                                            class="fa fa-check-circle"></i>
                                </button>
                                <?= form_close() ?>
                            <?php endif; ?>

                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12 text-right">
                        <?= $pagination ?>
                    </div>
                </div>
            </div>
        </div>
        <!-- End: life time stats -->
    </div>
</div>
<script>
    $("#ip-bind").click(function () {
        var remark = $("input[name='remark']").val();
        var ip = $("input[name='ip']").val();
        if (!remark) {
            toastr.error('请输入使用该IP的账户！');
            return;
        }
        $("#ip-bind").attr('disabled','disabled');
        $.ajax({
            url: "<?= site_url('ip/shop_ip/ajaxAdd') ?>",
            method: "POST",
            data: {'ip': ip, 'remark': remark},
            dataType: 'JSON',
            success: function (res) {
                if (res.success){
                    toastr.success(res.msg);
                } else {
                    toastr.error(res.msg);
                }
                $("#ip-bind").removeAttr('disabled');
                setTimeout(function () {
                    location.reload();
                },1500);
            },
            fail: function (res) {
                console.log(res)
            }
        });
    })
</script>

<div class="modal fade" id="importModal">
    <div class="modal-dialog" role="document">
        <form method="post" action="<?= site_url('ip/shop_ip/importExcel') ?>" enctype="multipart/form-data">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span>
                    </button>
                    <h4 class="modal-title" id="exampleModalLabel">IP导入</h4>
                </div>
                <div class="modal-body">

                    <div class="form-group">
                        <label for="recipient-name" class="control-label"></label>
                        <input type="file" name="file" class="form-control">
                    </div>
                    <input type="hidden" name="operator_id" value="<?= $this->_user->id ?>">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-primary">确认导入</button>
                </div>
            </div>
        </form>
    </div>
</div>


<script>
    $("#import_xls").click(function () {
        $("#importModal").modal();
    });

    function defConfirm(url) {
        if (!confirm("谨慎操作，删除后不可撤回，确定要删除吗？")) {
            return false;
        }
        window.location.href = url;
        return true;
    }

    $(document).ready(function () {
        $("#reset").click(function () {
            var SelectArr = $("select");
            $("input[type='text']").val('');
            SelectArr.val('');
        });

    });
</script>
